Option Explicit

' ======================================================================
' 平台标识
' ======================================================================
Public Const PLATFORM_WIN32 As String = "win32"
Public Const PLATFORM_WIN64 As String = "win64"


' ======================================================================
' 获取操作系统信息的工具
' ======================================================================

' 检查当前程序是否运行在一个 64 位操作系统中
' @param Boolean
Public Function isRunIn64OS() As Boolean
    ' 获取环境变量: PROCESSOR_ARCHITECTURE
    Dim architecture As String
    architecture = Environ("PROCESSOR_ARCHITECTURE")
    
    ' 根据值判断操作系统是32位还是64位
    If architecture = "AMD64" Then
        isRunIn64OS = True
    ElseIf architecture = "IA64" Then
        isRunIn64OS = True
    Else
        isRunIn64OS = False
    End If
End Function

' 获取当前的平台标识
' 现在只支持两种平台标识的检查: win32, win64
'
' @return 平台标识字符串
Public Function getRuntimePlatformType() As String
    If isRunIn64OS Then
        getRuntimePlatformType = PLATFORM_WIN64
    Else
        getRuntimePlatformType = PLATFORM_WIN32
    End If
End Function

' 检查字符串是否是一个支持的平台标识
' 现在只支持两种平台标识的检查
'   - `win32`，可以使用常量 `UtilsOS.PLATFORM_WIN32` 来进行比较
'   - `win64`，可以使用常量 `UtilsOS.PLATFORM_WIN64` 来进行比较
' @param str 任意字符串
' @return Boolean 参数是否是一个支持的平台标识
Public Function isEffectivePlatformType(ByRef str As String) As Boolean
    If str = PLATFORM_WIN32 Then
        isEffectivePlatformType = True
    ElseIf str = PLATFORM_WIN64 Then
        isEffectivePlatformType = True
    Else
        isEffectivePlatformType = False
    End If
End Function